﻿using BZ.Core.Frm;
using BZ.Core.TaskExt;
using BZ.Logger;
using DevComponents.DotNetBar;
using NDK.Module.BLL;
using NDK.Module.DAL;
using NDK.Module.Model;
using NDK.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace NDK.Frm
{
    public partial class Frm_Home : Form
    {
        private static log4net.ILog opLogger = log4net.LogManager.GetLogger("OPLogger");
        private static log4net.ILog m_Logger = log4net.LogManager.GetLogger("Frm_Home");
        private const int historyProgressMax = 64;
        private Func<int, DataItem, bool> updateOutputToDgv;
        private Action<Bar, bool> updateResultsProgress;
        private Action<Chart, Label, Label, Label, Label, Label> updateResultsToChart;
        private HistoryDataModel historyDataModel = new HistoryDataModel();
        private HistoryDataServices historyDataServices = new HistoryDataServices();
        private MeasureSizeServices measureSizeServices = new MeasureSizeServices();
        private MeasureSize measureSize = new MeasureSize();
        int userWidth = Screen.PrimaryScreen.Bounds.Width;
        private double[] singleSizeYields, singleSizeNGCount, singleSizeTotals;
        List<string> nameList = new List<string>();
        List<MeasureSize> sizes = null;

        private static List<PictureBox> pbTryList = new List<PictureBox>();


        private Frm_Home()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        /// <summary>
        /// 窗体对象实例，单例模式,保证整个工程只有一个实例
        /// </summary>
        private static Frm_Home _instance;
        private static readonly object singletonLock = new object();
        int errCount = 0;
        public int SocketErrNum = 0;
        public static Frm_Home Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (singletonLock)
                    {
                        if (_instance == null)
                        {
                            _instance = new Frm_Home();
                        }
                    }
                }
                return _instance;
            }
        }

        /// <summary>
        /// =================HOME界面加载=======================
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_Home_Load(object sender, EventArgs e)
        {

            #region UI设置
            int frToolbar1_Height = 86;
            int gap = userWidth / 130;
            int userHeight = Screen.PrimaryScreen.Bounds.Height - frToolbar1_Height - 4 * gap;
            #endregion

            #region 初始化饼图
            List<string> xData = new List<string>() { "NG", "OK" };
            List<int> yData = new List<int>() { 0, 1 };
            chart1.Series["Series1"].Label = "#VALX:#PERCENT{P}";
            chart1.Series["Series1"].Points.DataBindXY(xData, yData);
            chart1.Series["Series1"].Points[0].Color = Color.Red;
            chart1.Series["Series1"].Points[1].Color = Color.Green;
            this.tb_Result.Font = new System.Drawing.Font("Microsoft YaHei", 48F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134)));
            #endregion

            #region 绑定委托更新界面消息
            updateOutputToDgv += AddResults;
            updateResultsToChart += AddResultsToChart;
            #endregion

            #region 更新界面数据列表
            RefreshHomeUI(Common.CurProType);
            #endregion

            #region 读取点检和上传线性文件

            PublicMethod.ReadCSVFile();
            //try
            //{
            //    //读取点检文件
            //    string[] fileNames_book = FileUtils.GetFileNames(Common.pointCheckPath);
            //    foreach (string fileName in fileNames_book)
            //    {
            //        string temp = fileName.ToLower();//统一转换为小写

            //        if (temp.Contains("block_nomal.csv"))
            //        {
            //            Common.BlockNomalTable = FileUtils.OpenCSV(temp);
            //        }
            //        if (temp.Contains("grr_standard.csv"))
            //        {
            //            Common.GRRPointCheckTable = FileUtils.OpenCSV(temp);
            //        }
            //        if (temp.Contains("grrrange.csv"))
            //        {
            //            Common.GRRRangeTable = FileUtils.OpenCSV(temp);
            //        }
            //        if (temp.Contains("grr_fai.txt"))//读取需要点检的尺寸
            //        {
            //            Common.GRRPointCheckSize = FileUtils.ReadAllText(temp);
            //        }
            //    }
            //}
            //catch
            //{
            //    MessageBox.Show("读取点检文件失败!");
            //}

            //try
            //{
            //    //读取上传线性文件 
            //    //string ngConfig = "D:\\SWD\\ngConfig.txt";
            //    //string ngFAI = "D:\\SWD\\ngFAI.txt";
            //    //string t1 = FileUtils.ReadText(ngConfig, 0);
            //    //string limit = t1.Split(',')[1];
            //    //string select = t1.Split(',')[0];
            //    //Common.NgUpLimit = int.Parse(limit);
            //    //Common.NgSelectCount = int.Parse(select);

            //    //string ngNames = FileUtils.ReadAllText(ngFAI);
            //    //if (ngNames != "" && ngNames.Contains("FAI"))
            //    //{
            //    //    string[] ngNameArray = ngNames.Split(',');
            //    //    Common.NgNameList = ngNameArray.ToList();
            //    //}
            //}
            //catch
            //{
            //    MessageBox.Show("读取上传线性文件失败!");
            //}
            #endregion

            #region 结果输出(dgv,chart,panel) 绑定更新界面函数
            ProcessData.UpdateUIEvent += new delegateUpdateUI(UpdataUI);
            ProcessData.UpdateNGUIEvent += new delegateUpdateNGUI(UpdataNGUI);
            #endregion

            #region 读入历史数据
            ReadHistoryData();
            #endregion

            #region 保存数据到csv
            if (Common.isUploadApple == true)
                tb_ext.Text = Common.Line + "_" + Common.startDate;//默认CSV文件名
            else
                tb_ext.Text = Common.Line + "_" + Common.startDate;//默认CSV文件名

            Common.dataThread = Task.Factory.StartNew(() =>
            {
                int j = 0;

                //在输出文档的第二列增加NG/OK
                string Header = "Time,Position,Line,MeasureId,OK_NG,NG_FAI,Barcode";
                string USL = @",-,-,-,-,-,USL";
                string NOM = @",-,-,-,-,-,NOM";
                string LSL = @",-,-,-,-,-,LSL";

                MeasureSize measureSize;
                //MeasureSizeServices measureSizeService = new MeasureSizeServices();
                //List<MeasureSize> measureSizeList = measureSizeService.GetAllByProjectNameAndTurnNum(Common.ProjectName, 0);
                while (true)
                {
                    Thread.Sleep(5);
                    try
                    {
                        if (Common.waitingForWriteToDatabaseDataQueue.TryDequeue(out MeasureProduct measureProduct))
                        {
                            string values = "";
                            string currentProjectName = Common.ProjectName;
                            List<HistoryDataModel> historyDataList = new List<HistoryDataModel>();
                            foreach (var dataItem in measureProduct.MeasureData)
                            {
                                if (Common.whichBlock == 0)
                                {
                                    measureSize = measureSizeServices.GetModelByProjectNameAndSizeName("MIN", dataItem.Name);
                                }
                                else if (Common.whichBlock == 1)
                                {
                                    measureSize = measureSizeServices.GetModelByProjectNameAndSizeName("MID", dataItem.Name);
                                }
                                else if (Common.whichBlock == 2)
                                {
                                    measureSize = measureSizeServices.GetModelByProjectNameAndSizeName("MAX", dataItem.Name);
                                }
                                else
                                {
                                    measureSize = measureSizeServices.GetModelByProjectNameAndSizeName(currentProjectName, dataItem.Name);
                                }
                                if (measureSize == null) continue;
                                if (measureSize.IsShow == false) continue;
                                //保存到数据到CSV中  表头
                                values += string.IsNullOrEmpty(values) ? dataItem.Value.ToString("0.0000") : ("," + dataItem.Value.ToString("0.0000"));
                                Header += ("," + measureSize.SizeName);//
                                USL += ("," + measureSize.UpperDeviation);//+ "TOL+"
                                NOM += ("," + measureSize.NormValue);
                                LSL += ("," + (measureSize.LowerDeviation < 0.0000001 ? "0" : ("-" + measureSize.LowerDeviation).ToString()));//+ "TOL-"
                            }

                            string str = string.Empty;
                            str += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ",";
                            str += measureProduct.Position + ",";
                            str += Common.Line + ",";
                            j++;
                            str += j.ToString() + ",";
                            str += measureProduct.OK_NG + ",";
                            str += measureProduct.NG_FAI + ",";
                            if (measureProduct.SN == "")
                            {
                                measureProduct.SN = "_";
                            }
                            str += measureProduct.SN;
                            values = str + "," + values;

                            //创建存数据的路径
                            string CSVDataDirectory = "";
                            if ((Common.isUploadMes || Common.isUploadApple) && Common.isBlockModel == false) //上传
                            {
                                CSVDataDirectory = Common.dataSavePath + "\\" + Common.ProjectName + "\\" + DateTime.Now.ToString("yyyy-MM") + "\\" + "Upload Data";
                            }
                            if (Common.isPointCheck == false)//离线
                            {
                                CSVDataDirectory = Common.dataSavePath + "\\" + Common.ProjectName + "\\" + DateTime.Now.ToString("yyyy-MM") + "\\" + "Local Data" + "\\" + DateTime.Now.ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                CSVDataDirectory = Common.dataSavePath + "\\" + Common.ProjectName + "\\" + DateTime.Now.ToString("yyyy-MM") + "\\" + "Point Check" + "\\" + DateTime.Now.ToString("yyyy-MM-dd");
                            }
                            //if(Common.pointCheck==true)
                            //{
                            //    CSVDataDirectory = Common.dataSavePath + "\\" + Common.ProjectName + "\\" + DateTime.Now.ToString("yyyy-MM") + "\\" + "Point Check" + "\\" + DateTime.Now.ToString("yyyy-MM-dd");
                            //}
                            if (!Directory.Exists(CSVDataDirectory))
                            {
                                Directory.CreateDirectory(CSVDataDirectory);
                            }
                            string fullPath = CSVDataDirectory + @"\" + tb_ext.Text.Trim() + ".csv";

                            //写csv表头
                            if (!File.Exists(fullPath))
                            {
                                FileUtils.AppendText(fullPath, Header + "\r\n");
                                FileUtils.AppendText(fullPath, USL + "\r\n");
                                FileUtils.AppendText(fullPath, NOM + "\r\n");
                                FileUtils.AppendText(fullPath, LSL + "\r\n");
                            }
                            FileUtils.AppendText(fullPath, values + "\r\n");

                            m_Logger.Debug("数据库和CSV保存线程正在运行...");
                        }

                    }
                    catch (Exception ex)
                    {
                        Common.AppendUiLog.Log("保存CSV数据异常!" + ex.ToString(), LogType.Error);
                        m_Logger.Debug("CSV保存异常");
                    }
                }
            });
            #endregion

            Task.Factory.StartNew(new Action(() =>
            {
                while (true)
                {
                    Thread.Sleep(10);
                    LoadCt();
                }
            }));

            if (Common.Line != "MUR")
            {
                label33.Visible = false;
                TB_mdlCode.Visible = false;
                Btn_Save.Visible = false;
            }
            //UpdateResultList();
        }

        public void LoadCt()
        {
            Frm_Home.Instance.BeginInvoke(new Action(() =>
            {

                lbl_CT.Text = "CT: " + Common.CtLook.TotalSeconds.ToString("F2");
                label4.Text = "上料Tray盘定位CT: " + Common.CtLook0.TotalSeconds.ToString("F2");
                label6.Text = "产品1上料定位CT: " + Common.CtLook1.TotalSeconds.ToString("F2");
                label7.Text = "产品2上料定位CT: " + Common.CtLook2.TotalSeconds.ToString("F2");
                label9.Text = "扫码工位CT: " + Common.CtLook3.TotalSeconds.ToString("F2"); ;
                label10.Text = "上料平台1CT: " + Common.CtLook4.TotalSeconds.ToString("F2");
                label11.Text = "上料平台2CT: " + Common.CtLook5.TotalSeconds.ToString("F2");
                label12.Text = "PPG工位CT: " + Common.CtLook6.TotalSeconds.ToString("F2");
                label13.Text = "翻转取料工位CT: " + Common.CtLook7.TotalSeconds.ToString("F2");
                label31.Text = "翻转放料工位CT: " + Common.CtLook8.TotalSeconds.ToString("F2");
                label14.Text = "上料移栽工位CT: " + Common.CtLook9.TotalSeconds.ToString("F2");
                label15.Text = "量测工位CT: " + Common.CtLook10.TotalSeconds.ToString("F2");
                label16.Text = "下料翻转工位CT: " + Common.CtLook11.TotalSeconds.ToString("F2");
                label17.Text = "下料Tray盘定位CT: " + Common.CtLook12.TotalSeconds.ToString("F2");

            }));
        }

        public void ReadHistoryData()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic = INIUtils.GetAllKeyValues(Common.ProjectName);
            //投入数
            string strTotal = "";
            dic.TryGetValue("Total", out strTotal);
            if (strTotal != null)
                Common.TotalCount = int.Parse(strTotal);
            //OK数
            string strOKCount = "";
            dic.TryGetValue("OKCount", out strOKCount);
            if (strOKCount != null)
                Common.OKCount = int.Parse(strOKCount);
            Common.NGCount = Common.TotalCount - Common.OKCount;

            //单尺寸良率
            int count = dgv_ResultOutputRote.ColumnCount - 1;
            string[] singleSizeTotalss = new string[count];
            string[] singleSizeYieldss = new string[count];
            string[] singleSizeNGCountss = new string[count];
            for (int i = 0; i < count; i++)
            {
                dic.TryGetValue("singleSizeTotals" + i.ToString(), out singleSizeTotalss[i]);
                dic.TryGetValue("singleSizeYields" + i.ToString(), out singleSizeYieldss[i]);
                dic.TryGetValue("singleSizeNGCount" + i.ToString(), out singleSizeNGCountss[i]);
                if (singleSizeTotalss[i] != null)
                {
                    singleSizeTotals[i] = double.Parse(singleSizeTotalss[i]);
                }
                if (singleSizeYieldss[i] != null)
                {
                    singleSizeYields[i] = double.Parse(singleSizeYieldss[i]);
                }
                if (singleSizeNGCountss[i] != null)
                {
                    singleSizeNGCount[i] = double.Parse(singleSizeNGCountss[i]);
                }
            }

            AddResultsToChart(chart1, lbl_CT, lbl_Total, OKLab, NGLab, NALab);
            updataUI(dgv_ResultOutputRote.ColumnCount - 1);
        }

        public void RefreshHomeUI(string productType)
        {
            #region 读取数据库中各个尺寸
            MeasureSizeServices measureSizeService = new MeasureSizeServices();
            if (productType == "Block")
            {
                if (Common.whichBlock == 0)
                {
                    sizes = measureSizeService.GetAllByProjectNameAndTurnNum("MIN", 0);
                }
                else if (Common.whichBlock == 1)
                {
                    sizes = measureSizeService.GetAllByProjectNameAndTurnNum("MID", 0);
                }
                else
                {
                    sizes = measureSizeService.GetAllByProjectNameAndTurnNum("MAX", 0);
                }

            }
            if (productType == "Product")
            {
                sizes = measureSizeService.GetAllByProjectNameAndTurnNum(Common.ProjectName, 0);
            }


            if (sizes == null)
            {
                return;
            }

            int sizeCount = 0;
            nameList = new List<string>();
            foreach (MeasureSize size in sizes)
            {
                if (size.IsShow == true)
                {
                    sizeCount++;
                    //dgv显示的所有尺寸名称
                    nameList.Add(size.SizeName);
                }
            }
            singleSizeYields = new double[sizeCount];
            singleSizeNGCount = new double[sizeCount];
            singleSizeTotals = new double[sizeCount];
            #endregion

            #region 设置固定列表头
            dgv_ResultOutput.Columns.Clear();
            dgv_NGResultOutput.Columns.Clear();
            dgv_ResultOutputRote.Columns.Clear();

            string[] str = new string[4] { " ", "Time", "Barcode", "Pos" };
            string[] str1 = new string[5] { " ", "NGFAI", "Time", "Barcode", "Pos" };

            for (int i = 0; i < 4; i++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                acCode.Name = str[i];
                acCode.DataPropertyName = str[i];
                acCode.ReadOnly = true;
                acCode.SortMode = DataGridViewColumnSortMode.NotSortable;
                dgv_ResultOutput.Columns.Add(acCode);
            }

            for (int i = 0; i < str1.Length; i++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                acCode.Name = str1[i];
                acCode.DataPropertyName = str1[i];
                acCode.ReadOnly = true;
                acCode.SortMode = DataGridViewColumnSortMode.NotSortable;
                dgv_NGResultOutput.Columns.Add(acCode);
            }

            for (int i = 0; i < 1; i++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                acCode.Name = "";
                acCode.DataPropertyName = "";
                acCode.ReadOnly = true;
                acCode.SortMode = DataGridViewColumnSortMode.NotSortable;
                dgv_ResultOutputRote.Columns.Add(acCode);
            }
            #endregion

            #region 显示OK产品的列表
            int showIndex = -1;
            for (int Index = 0; Index < sizes.Count; Index++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                if (sizes[Index].IsShow == true)
                {
                    showIndex = showIndex + 1;
                    acCode.Name = sizes[Index].SizeName;
                    acCode.DataPropertyName = sizes[Index].SizeName;
                    acCode.ReadOnly = true;
                    acCode.SortMode = DataGridViewColumnSortMode.NotSortable;

                    if (sizes[Index].IsJudging == false)
                        acCode.HeaderCell.Style.ForeColor = Color.YellowGreen;
                    else
                        acCode.HeaderCell.Style.ForeColor = Color.Green;

                    acCode.HeaderText = sizes[Index].SizeName;// + "," + "(" + sizes[Index].NormValue + " | " + sizes[Index].UpperDeviation + " | " + sizes[Index].LowerDeviation + ")";
                    dgv_ResultOutput.Columns.Add(acCode);
                }
            }

            #region 建立尺寸上下限固定行
            dgv_ResultOutput.Rows.Clear();
            try
            {
                DataGridViewRow drUpper = new DataGridViewRow();
                DataGridViewRow drNorma = new DataGridViewRow();
                DataGridViewRow drLower = new DataGridViewRow();
                drUpper.CreateCells(dgv_ResultOutput);
                drNorma.CreateCells(dgv_ResultOutput);
                drLower.CreateCells(dgv_ResultOutput);
                drUpper.ReadOnly = true;
                drNorma.ReadOnly = true;
                drLower.ReadOnly = true;

                //USL前端
                drUpper.Cells[0].Value = "Tol(+)";
                drUpper.Cells[1].Value = "-";
                drUpper.Cells[2].Value = "-";
                drUpper.Cells[3].Value = "-";

                drUpper.Cells[0].Style.BackColor = Color.Black;
                drUpper.Cells[1].Style.BackColor = Color.Black;
                drUpper.Cells[2].Style.BackColor = Color.Black;
                drUpper.Cells[3].Style.BackColor = Color.Black;

                drUpper.Cells[0].Style.ForeColor = Color.White;
                drUpper.Cells[1].Style.ForeColor = Color.White;
                drUpper.Cells[2].Style.ForeColor = Color.White;
                drUpper.Cells[3].Style.ForeColor = Color.White;

                drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                drUpper.Cells[3].Style.Font = new Font("隶书", 12);

                //Nom前端
                drNorma.Cells[0].Value = "Target";
                drNorma.Cells[1].Value = "-";
                drNorma.Cells[2].Value = "-";
                drNorma.Cells[3].Value = "-";

                drNorma.Cells[0].Style.BackColor = Color.Black;
                drNorma.Cells[1].Style.BackColor = Color.Black;
                drNorma.Cells[2].Style.BackColor = Color.Black;
                drNorma.Cells[3].Style.BackColor = Color.Black;

                drNorma.Cells[0].Style.ForeColor = Color.White;
                drNorma.Cells[1].Style.ForeColor = Color.White;
                drNorma.Cells[2].Style.ForeColor = Color.White;
                drNorma.Cells[3].Style.ForeColor = Color.White;

                drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                drNorma.Cells[3].Style.Font = new Font("隶书", 12);

                //LSL前端
                drLower.Cells[0].Value = "Tol(-)";
                drLower.Cells[1].Value = "-";
                drLower.Cells[2].Value = "-";
                drLower.Cells[3].Value = "-";

                drLower.Cells[0].Style.BackColor = Color.Black;
                drLower.Cells[1].Style.BackColor = Color.Black;
                drLower.Cells[2].Style.BackColor = Color.Black;
                drLower.Cells[3].Style.BackColor = Color.Black;

                drLower.Cells[0].Style.ForeColor = Color.White;
                drLower.Cells[1].Style.ForeColor = Color.White;
                drLower.Cells[2].Style.ForeColor = Color.White;
                drLower.Cells[3].Style.ForeColor = Color.White;

                drLower.Cells[0].Style.Font = new Font("隶书", 12);
                drLower.Cells[1].Style.Font = new Font("隶书", 12);
                drLower.Cells[2].Style.Font = new Font("隶书", 12);
                drLower.Cells[3].Style.Font = new Font("隶书", 12);


                //判定每个尺寸
                for (int index = 0; index < dgv_ResultOutput.Columns.Count - 4; index++)
                {
                    //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                    //获得上限、理论值、下限
                    for (int jj = 0; jj < sizes.Count; jj++)
                    {
                        if (sizes[jj].SizeName == dgv_ResultOutput.Columns[index + 4].HeaderText)
                        {
                            drUpper.Cells[index + 4].Value = sizes[jj].UpperDeviation.ToString();
                            drNorma.Cells[index + 4].Value = sizes[jj].NormValue.ToString();

                            if (sizes[jj].LowerDeviation == 0)
                            {
                                drLower.Cells[index + 4].Value = sizes[jj].LowerDeviation.ToString();
                            }
                            else
                            {
                                drLower.Cells[index + 4].Value = "-" + sizes[jj].LowerDeviation.ToString();
                            }

                            drUpper.Cells[index + 4].Style.BackColor = Color.Black;
                            drNorma.Cells[index + 4].Style.BackColor = Color.Black;
                            drLower.Cells[index + 4].Style.BackColor = Color.Black;

                            drUpper.Cells[index + 4].Style.ForeColor = Color.White;
                            drNorma.Cells[index + 4].Style.ForeColor = Color.White;
                            drLower.Cells[index + 4].Style.ForeColor = Color.White;

                            drUpper.Cells[index + 4].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[index + 4].Style.Font = new Font("隶书", 12);
                            drLower.Cells[index + 4].Style.Font = new Font("隶书", 12);
                        }
                    }
                }
                dgv_ResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                dgv_ResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                dgv_ResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                dgv_ResultOutput.Rows[2].Frozen = true;      //冻结前三行
            }
            catch (Exception exc)
            {
            }
            #endregion
            #endregion

            #region 显示NG产品的列表
            int showIndex_NG = -1;
            for (int Index = 0; Index < sizes.Count; Index++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                if (sizes[Index].IsShow == true)
                {
                    showIndex_NG = showIndex_NG + 1;

                    acCode.Name = sizes[Index].SizeName;
                    acCode.DataPropertyName = sizes[Index].SizeName;
                    acCode.ReadOnly = true;
                    acCode.SortMode = DataGridViewColumnSortMode.NotSortable;

                    if (sizes[Index].IsJudging == false)
                        acCode.HeaderCell.Style.ForeColor = Color.YellowGreen;
                    else
                        acCode.HeaderCell.Style.ForeColor = Color.Green;
                    acCode.HeaderText = sizes[Index].SizeName;// + "," + "(" + sizes[Index].NormValue + " | " + sizes[Index].UpperDeviation + " | " + sizes[Index].LowerDeviation + ")";
                    dgv_NGResultOutput.Columns.Add(acCode);
                }
            }

            #region 建立尺寸上下限固定行
            dgv_NGResultOutput.Rows.Clear();
            try
            {
                DataGridViewRow drUpper = new DataGridViewRow();
                DataGridViewRow drNorma = new DataGridViewRow();
                DataGridViewRow drLower = new DataGridViewRow();
                drUpper.CreateCells(dgv_NGResultOutput);
                drNorma.CreateCells(dgv_NGResultOutput);
                drLower.CreateCells(dgv_NGResultOutput);
                drUpper.ReadOnly = true;
                drNorma.ReadOnly = true;
                drLower.ReadOnly = true;

                //USL前端
                drUpper.Cells[0].Value = "Tol(+)";
                drUpper.Cells[1].Value = "-";
                drUpper.Cells[2].Value = "-";
                drUpper.Cells[3].Value = "-";
                drUpper.Cells[4].Value = "-";

                drUpper.Cells[0].Style.BackColor = Color.Black;
                drUpper.Cells[1].Style.BackColor = Color.Black;
                drUpper.Cells[2].Style.BackColor = Color.Black;
                drUpper.Cells[3].Style.BackColor = Color.Black;
                drUpper.Cells[4].Style.BackColor = Color.Black;

                drUpper.Cells[0].Style.ForeColor = Color.White;
                drUpper.Cells[1].Style.ForeColor = Color.White;
                drUpper.Cells[2].Style.ForeColor = Color.White;
                drUpper.Cells[3].Style.ForeColor = Color.White;
                drUpper.Cells[4].Style.ForeColor = Color.White;

                drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                drUpper.Cells[3].Style.Font = new Font("隶书", 12);
                drUpper.Cells[4].Style.Font = new Font("隶书", 12);

                //Nom前端
                drNorma.Cells[0].Value = "Target";
                drNorma.Cells[1].Value = "-";
                drNorma.Cells[2].Value = "-";
                drNorma.Cells[3].Value = "-";
                drNorma.Cells[4].Value = "-";

                drNorma.Cells[0].Style.BackColor = Color.Black;
                drNorma.Cells[1].Style.BackColor = Color.Black;
                drNorma.Cells[2].Style.BackColor = Color.Black;
                drNorma.Cells[3].Style.BackColor = Color.Black;
                drNorma.Cells[4].Style.BackColor = Color.Black;

                drNorma.Cells[0].Style.ForeColor = Color.White;
                drNorma.Cells[1].Style.ForeColor = Color.White;
                drNorma.Cells[2].Style.ForeColor = Color.White;
                drNorma.Cells[3].Style.ForeColor = Color.White;
                drNorma.Cells[4].Style.ForeColor = Color.White;

                drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                drNorma.Cells[3].Style.Font = new Font("隶书", 12);
                drNorma.Cells[4].Style.Font = new Font("隶书", 12);

                //LSL前端
                drLower.Cells[0].Value = "Tol(-)";
                drLower.Cells[1].Value = "-";
                drLower.Cells[2].Value = "-";
                drLower.Cells[3].Value = "-";
                drLower.Cells[4].Value = "-";

                drLower.Cells[0].Style.BackColor = Color.Black;
                drLower.Cells[1].Style.BackColor = Color.Black;
                drLower.Cells[2].Style.BackColor = Color.Black;
                drLower.Cells[3].Style.BackColor = Color.Black;
                drLower.Cells[4].Style.BackColor = Color.Black;

                drLower.Cells[0].Style.ForeColor = Color.White;
                drLower.Cells[1].Style.ForeColor = Color.White;
                drLower.Cells[2].Style.ForeColor = Color.White;
                drLower.Cells[3].Style.ForeColor = Color.White;
                drLower.Cells[4].Style.ForeColor = Color.White;

                drLower.Cells[0].Style.Font = new Font("隶书", 12);
                drLower.Cells[1].Style.Font = new Font("隶书", 12);
                drLower.Cells[2].Style.Font = new Font("隶书", 12);
                drLower.Cells[3].Style.Font = new Font("隶书", 12);
                drLower.Cells[4].Style.Font = new Font("隶书", 12);


                //判定每个尺寸
                for (int index = 0; index < dgv_NGResultOutput.Columns.Count - 5; index++)
                {
                    //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                    //获得上限、理论值、下限
                    for (int jj = 0; jj < sizes.Count; jj++)
                    {
                        if (sizes[jj].SizeName == dgv_NGResultOutput.Columns[index + 5].HeaderText)
                        {
                            drUpper.Cells[index + 5].Value = sizes[jj].UpperDeviation.ToString();
                            drNorma.Cells[index + 5].Value = sizes[jj].NormValue.ToString();

                            if (sizes[jj].LowerDeviation == 0)
                            {
                                drLower.Cells[index + 5].Value = sizes[jj].LowerDeviation.ToString();
                            }
                            else
                            {
                                drLower.Cells[index + 5].Value = "-" + sizes[jj].LowerDeviation.ToString();
                            }

                            drUpper.Cells[index + 5].Style.BackColor = Color.Black;
                            drNorma.Cells[index + 5].Style.BackColor = Color.Black;
                            drLower.Cells[index + 5].Style.BackColor = Color.Black;

                            drUpper.Cells[index + 5].Style.ForeColor = Color.White;
                            drNorma.Cells[index + 5].Style.ForeColor = Color.White;
                            drLower.Cells[index + 5].Style.ForeColor = Color.White;

                            drUpper.Cells[index + 5].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[index + 5].Style.Font = new Font("隶书", 12);
                            drLower.Cells[index + 5].Style.Font = new Font("隶书", 12);
                        }
                    }
                }
                dgv_NGResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                dgv_NGResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                dgv_NGResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                dgv_NGResultOutput.Rows[2].Frozen = true;      //冻结前三行
            }
            catch (Exception exc)
            {
            }
            #endregion
            #endregion

            #region 显示良率的列表
            int showIndex_Rote = -1;
            for (int Index = 0; Index < sizes.Count; Index++)
            {
                DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn();
                if (sizes[Index].IsJudging == false)
                    acCode.HeaderCell.Style.ForeColor = Color.YellowGreen;
                else
                    acCode.HeaderCell.Style.ForeColor = Color.Green;
                if (sizes[Index].IsShow == true)
                {
                    showIndex_Rote = showIndex_Rote + 1;
                    acCode.Name = sizes[Index].SizeName;
                    acCode.DataPropertyName = sizes[Index].SizeName;
                    acCode.HeaderText = sizes[Index].SizeName;
                    acCode.ReadOnly = true;
                    acCode.SortMode = DataGridViewColumnSortMode.NotSortable;
                    dgv_ResultOutputRote.Columns.Add(acCode);
                }
            }

            string[] RowName = new string[4];

            RowName[0] = "良率";
            dgv_ResultOutputRote.BackgroundColor = Color.Black;
            dgv_ResultOutputRote.ForeColor = Color.Green;
            dgv_ResultOutputRote.Font = new Font("隶书", 12);
            dgv_ResultOutputRote.ReadOnly = true;

            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "Total";
            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "OK";
            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "NG";
            dgv_ResultOutputRote.Rows.Add(RowName);

            singleSizeYields = new double[sizeCount];
            singleSizeNGCount = new double[sizeCount];
            singleSizeTotals = new double[sizeCount];
            #endregion
        }

        #region UI
        /// <summary>
        /// 显示数据栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonItem_Data_Click(object sender, EventArgs e)
        {
            dotNetBarManager1.SuspendLayout = true;
            try
            {
                foreach (Bar bar in dotNetBarManager1.Bars)
                {
                    bar.TabNavigation = true;//防止拖拽后，导航栏消失
                    if (bar.DockSide == eDockSide.None)//防止拖拽后，未停靠到Document，就关闭tab
                    {
                        bar.DockSide = eDockSide.Document;
                    }
                    if (bar.DockSide == eDockSide.Document)
                    {
                        foreach (DockContainerItem dock in bar.Items)
                        {
                            if (dock.Name == "dockContainerItem_Data")
                            {
                                dock.Visible = true;
                                if (!bar.Visible)
                                    bar.Visible = true;
                            }
                        }
                    }
                }
            }
            finally
            {
                dotNetBarManager1.SuspendLayout = false;
            }
        }
        /// <summary>
        /// 显示所有栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonItem_All_Click(object sender, EventArgs e)
        {
            dotNetBarManager1.SuspendLayout = true;
            try
            {
                foreach (Bar bar in dotNetBarManager1.Bars)
                {
                    bar.TabNavigation = true;
                    if (bar.DockSide == eDockSide.None)
                    {
                        if (bar.Name == "bar_Statistics")
                        {
                            bar.DockSide = eDockSide.Left;
                        }
                        else if (bar.Name == "bar_Log")
                        {
                            bar.DockSide = eDockSide.Bottom;
                        }
                        else
                        {
                            bar.DockSide = eDockSide.Document;
                        }
                    }
                    if (bar.DockSide == eDockSide.Document
                        || bar.DockSide == eDockSide.Bottom
                        || bar.DockSide == eDockSide.Left
                        || bar.DockSide == eDockSide.Right)
                    {
                        foreach (DockContainerItem dock in bar.Items)
                        {
                            dock.Visible = true;
                            if (!bar.Visible)
                                bar.Visible = true;
                        }
                    }
                }
            }
            finally
            {
                dotNetBarManager1.SuspendLayout = false;
            }
        }
        /// <summary>
        /// 显示图像栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonItem_Image_Click(object sender, EventArgs e)
        {
            dotNetBarManager1.SuspendLayout = true;
            try
            {
                foreach (Bar bar in dotNetBarManager1.Bars)
                {
                    bar.TabNavigation = true;
                    if (bar.DockSide == eDockSide.None)
                    {
                        bar.DockSide = eDockSide.Document;
                    }
                    if (bar.DockSide == eDockSide.Document)
                    {
                        foreach (DockContainerItem dock in bar.Items)
                        {
                            if (dock.Name == "dockContainerItem_Image")
                            {
                                dock.Visible = true;
                                if (!bar.Visible)
                                    bar.Visible = true;
                            }
                        }
                    }
                }
            }
            finally
            {
                dotNetBarManager1.SuspendLayout = false;
            }
        }

        /// <summary>
        /// 显示日志栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonItem_Log_Click(object sender, EventArgs e)
        {
            dotNetBarManager1.SuspendLayout = true;
            try
            {
                foreach (Bar bar in dotNetBarManager1.Bars)
                {
                    if (bar.Name == "bar_Log")
                    {
                        bar.TabNavigation = true;
                        foreach (DockContainerItem dock in bar.Items)
                        {
                            dock.Visible = true;
                            if (!bar.Visible)
                                bar.Visible = true;
                        }
                        break;
                    }
                }
            }
            finally
            {
                dotNetBarManager1.SuspendLayout = false;
            }
        }
        #endregion

        #region 解决闪烁问题
        /// <summary>
        /// 解决闪烁问题
        /// </summary>
        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams cp = base.CreateParams;
        //        cp.ExStyle |= 0x02000000;
        //        return cp;
        //    }
        //}
        #endregion

        public bool AddResults(int MeasureID, DataItem camaraData)
        {
            string SizeName = camaraData.Name;
            double MeasureValue = camaraData.Value;
            if (!nameList.Contains(camaraData.Name))
                return false;//如果尺寸不需要显示，返回false
            if (!dgv_ResultOutput.InvokeRequired)
            {
                for (int rowIndex = 0; rowIndex < dgv_ResultOutput.Rows.Count; rowIndex++)
                {
                    if (dgv_ResultOutput.Rows[rowIndex].Cells[1].Value.ToString() != camaraData.Name)
                        continue;

                    if (camaraData.JugeResult == JUDGEMENT_RESULT.NG.ToString())//NG
                    {
                        dgv_ResultOutput.Rows[rowIndex].Cells[3].Style.BackColor = Color.Red;
                    }
                    else
                    {
                        dgv_ResultOutput.Rows[rowIndex].Cells[3].Style.BackColor = Color.White;
                    }

                    dgv_ResultOutput.Rows[rowIndex].Cells[3].Value = camaraData.Value.ToString("0.0000");
                    dgv_ResultOutput.Rows[rowIndex].Cells[0].Value = MeasureID;
                    dgv_ResultOutput.Rows[rowIndex].Cells[7].Value = (camaraData.Value - double.Parse(dgv_ResultOutput.Rows[rowIndex].Cells[4].Value.ToString())).ToString("f6");
                    return true;
                }
            }
            else
            {
                this.BeginInvoke(updateOutputToDgv, new object[] { MeasureID, camaraData });
            }
            return true;

        }

        /// <summary>
        /// 更新饼图结果
        /// </summary>
        /// <param name="ret"></param>
        public void AddResultsToChart(Chart chart, Label lbl_CT, Label lbl_Total, Label OKLab, Label NGLab, Label NALab)
        {
            List<string> xData = new List<string>() { "NG", "OK" };
            //NGCount = Common.NGCount
            SaveYieldToIni();
            List<int> yData = new List<int>() { Common.NGCount, Common.TotalCount - Common.NGCount };
            if (!lbl_CT.InvokeRequired)
            {
                chart.Series["Series1"].Label = "#VALX:#PERCENT{P}";

                chart.Series["Series1"].Points[0].Color = Color.Red;
                chart.Series["Series1"].Points[1].Color = Color.Green;
                chart.Series["Series1"].Points.DataBindXY(xData, yData);

                lbl_Total.Text = "Total:" + Common.TotalCount;
                lbl_Exception.Text = "异常:" + Common.ExceptionCount;
                OKLab.Text = (Common.TotalCount - Common.NGCount).ToString();
                NGLab.Text = Common.NGCount.ToString();

                //lbl_CT.Text = "CT: " + Common.TotalCT.ToString("0.000") + " S";

                double str = 100;
                if (Common.TotalCount == 0)
                {
                    str = 100.00;
                }
                else
                {
                    str = ((Common.TotalCount - Common.NGCount) / Common.TotalCount) * 100.00; //良率
                }

                //if (str < Common.RatePresentSetting) //当前良率小于设定值，则弹窗
                //{
                //    if (Common.b_DisplayNot == false)
                //    {
                //        string ss = "当前良率为：" + str.ToString("#0.00") + "%" + ", " + "小于设置的良率< " + Common.RatePresentSetting.ToString("#0.00") + "%" + " >" + "，请注意！";
                //        hint(Frm_Home.Instance, ss);
                //        Common.b_rateLow = true;
                //    }
                //    else
                //    {
                //        Common.b_rateLow = false;
                //        Dlg_Warning.Instance.Hide();
                //    }
                //}
                //else
                //{
                //    Common.b_rateLow = false;
                //    Dlg_Warning.Instance.Hide();
                //}
            }
            else
            {
                this.BeginInvoke(updateResultsToChart, new object[] { chart, lbl_CT, lbl_Total, OKLab, NGLab });
            }
        }

        /// <summary>
        /// 保存对应产品OK数和Total总数,保存各尺寸的良率
        /// </summary>
        private void SaveYieldToIni()
        {
            //保存对应产品OK数和Total总数
            INIUtils.Write(Common.ProjectName, "OKCount", (Common.TotalCount - Common.NGCount).ToString());
            INIUtils.Write(Common.ProjectName, "Total", (Common.TotalCount).ToString());
            INIUtils.Write(Common.ProjectName, "ExceptionCount", (Common.ExceptionCount).ToString());

            //保存各尺寸的良率
            int count = dgv_ResultOutputRote.ColumnCount - 1;
            for (int i = 0; i < count; i++)
            {
                INIUtils.Write(Common.ProjectName, "singleSizeTotals" + i.ToString(), singleSizeTotals[i].ToString());
                INIUtils.Write(Common.ProjectName, "singleSizeYields" + i.ToString(), singleSizeYields[i].ToString());
                INIUtils.Write(Common.ProjectName, "singleSizeNGCount" + i.ToString(), singleSizeNGCount[i].ToString());
            }
        }


        private void updataUI(int count)
        {
            for (int index = 0; index < count; index++)
            {
                //计算单个尺寸的良率
                if (singleSizeTotals[index] != 0)
                {
                    singleSizeYields[index] = (singleSizeTotals[index] - singleSizeNGCount[index]) / Convert.ToDouble(singleSizeTotals[index]);
                }
                else
                {
                    singleSizeYields[index] = 0;
                }

                //单个尺寸的良率显示
                dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.BackColor = Color.Black;
                dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.ForeColor = Color.Green;
                dgv_ResultOutputRote.Rows[0].Cells[index + 1].Value = (singleSizeYields[index] * 100).ToString("f2") + "%";

                //单个尺寸的测量总数显示
                dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.BackColor = Color.Black;
                dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.ForeColor = Color.Green;
                dgv_ResultOutputRote.Rows[1].Cells[index + 1].Value = singleSizeTotals[index].ToString();

                //单个尺寸的测量的OK数的显示
                dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.BackColor = Color.Black;
                dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.ForeColor = Color.Green;
                dgv_ResultOutputRote.Rows[2].Cells[index + 1].Value = (singleSizeTotals[index] - singleSizeNGCount[index]).ToString();

                //单个尺寸的测量的NG数的显示
                dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.BackColor = Color.Black;
                dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.ForeColor = Color.Green;
                dgv_ResultOutputRote.Rows[3].Cells[index + 1].Value = singleSizeNGCount[index].ToString();
            }
        }

        private void Frm_Home_FormClosing(object sender, FormClosingEventArgs e)
        {
        }
        /// <summary>
        /// 导出home界面的数据到csv
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cms_OutputToCsv_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == tsmi_SaveToExcel)
            {
                //FileUtils.SaveCSV((DataTable)(dgv_ResultOutput.DataSource), @"D:\Data\output\data");
            }
        }
        /// <summary>
        /// 导出home界面的数据到csv
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cms_Log_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == tsmi_Clear)
            {
                dataGridViewLogBoard1.dataGridView.Rows.Clear();
            }
        }
        /// <summary>
        /// 不断更新home页面的CT显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_CT_Tick(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 更新数据到界面
        /// </summary>
        /// <param name="camaraDataList">当前测试产品的数据</param>
        private async void UpdataUI (MeasureProduct product)
        {
            List<DataItem> camaraDataList = product.MeasureData;
            if(camaraDataList == null)
                return;
            txtBarcode.Text = product.SN;
            string jugeRet = JUDGEMENT_RESULT.OK.ToString();

            DataGridViewRow dr = new DataGridViewRow();
            try
            {
                await Task.Run(() =>
                {
                    dr.CreateCells(dgv_ResultOutput);

                    //插入时间
                    dr.Cells[1].Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    dr.Cells[2].Value = product.SN;
                    dr.Cells[3].Value = product.Position;

                    dr.Cells[1].Style.ForeColor = Color.Green;
                    dr.Cells[2].Style.ForeColor = Color.Green;
                    dr.Cells[3].Style.ForeColor = Color.Green;

                    dr.Cells[0].Style.BackColor = Color.Black;
                    dr.Cells[1].Style.BackColor = Color.Black;
                    dr.Cells[2].Style.BackColor = Color.Black;
                    dr.Cells[3].Style.BackColor = Color.Black;

                    dr.Cells[1].Style.Font = new Font("隶书", 12);
                    dr.Cells[2].Style.Font = new Font("隶书", 12);
                    dr.Cells[3].Style.Font = new Font("隶书", 12);

                    foreach(DataItem camaraData in camaraDataList)
                    {

                        if(!nameList.Contains(camaraData.Name))
                            continue;

                        //判定每个尺寸
                        for(int index = 0; index < dgv_NGResultOutput.Columns.Count - 5; index++)
                        {
                            string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',');
                            if(str_FAI[0] != camaraData.Name)
                            {
                                continue;
                            }

                            //cell颜色改变
                            if(camaraData.JugeResult == JUDGEMENT_RESULT.NG.ToString() || camaraData.JugeResult == JUDGEMENT_RESULT.EXCEPTION.ToString())//NG or EXCEPTION
                            {
                                dr.Cells[index + 4].Style.BackColor = Color.Black;

                                dr.Cells[index + 4].Style.ForeColor = Color.Red;
                            }
                            else
                            {
                                dr.Cells[index + 4].Style.BackColor = Color.Black;

                                dr.Cells[index + 4].Style.ForeColor = Color.Green;
                            }

                            camaraData.Value = Math.Round(camaraData.Value, 4);
                            //插入该尺寸
                            if(camaraData.Value > 666)
                            {
                                dr.Cells[index + 4].Value = "N/A";
                            }
                            else
                            {

                                if(camaraData.Name.Contains("SAMPLE"))
                                { dr.Cells[index + 4].Value = camaraData.Value.ToString("0"); }
                                else
                                { dr.Cells[index + 4].Value = camaraData.Value.ToString("0.0000"); }//       
                            }


                            //单尺寸良率
                            singleSizeTotals[index]++;
                            if(camaraData.JugeResult == JUDGEMENT_RESULT.EXCEPTION.ToString())//异常也算入NG
                            {
                                jugeRet += JUDGEMENT_RESULT.NG.ToString();
                                singleSizeNGCount[index]++;
                            }
                            if(camaraData.JugeResult == JUDGEMENT_RESULT.NG.ToString())
                            {
                                jugeRet += JUDGEMENT_RESULT.NG.ToString();
                                singleSizeNGCount[index]++;
                            }
                            //计算单个尺寸的良率
                            if(singleSizeTotals[index] != 0)
                            {
                                singleSizeYields[index] = (singleSizeTotals[index] - singleSizeNGCount[index]) / Convert.ToDouble(singleSizeTotals[index]);
                            }
                            else
                            {
                                singleSizeYields[index] = 0;
                            }

                            dr.Cells[index + 4].Style.Font = new Font("隶书", 12);//0902add

                            //单个尺寸的良率显示
                            dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.BackColor = Color.Black;
                            dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.ForeColor = Color.Green;
                            dgv_ResultOutputRote.Rows[0].Cells[index + 1].Value = (singleSizeYields[index] * 100).ToString("f2") + "%";
                            //单个尺寸的测量总数显示
                            dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.BackColor = Color.Black;
                            dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.ForeColor = Color.Green;
                            dgv_ResultOutputRote.Rows[1].Cells[index + 1].Value = singleSizeTotals[index].ToString();
                            //单个尺寸的测量的OK数的显示
                            dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.BackColor = Color.Black;
                            dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.ForeColor = Color.Green;
                            dgv_ResultOutputRote.Rows[2].Cells[index + 1].Value = (singleSizeTotals[index] - singleSizeNGCount[index]).ToString();
                            //单个尺寸的测量的NG数的显示
                            dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.BackColor = Color.Black;
                            dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.ForeColor = Color.Green;
                            dgv_ResultOutputRote.Rows[3].Cells[index + 1].Value = singleSizeNGCount[index].ToString();

                        }
                    }
                });
                //新增加一行在第一行
                BeginInvoke(new Action(() =>
                {
                    if(dgv_ResultOutput.Rows.Count >= 64)
                    {
                        #region 建立尺寸上下限固定行
                        dgv_ResultOutput.Rows.Clear();
                        try
                        {
                            DataGridViewRow drUpper = new DataGridViewRow();
                            DataGridViewRow drNorma = new DataGridViewRow();
                            DataGridViewRow drLower = new DataGridViewRow();
                            drUpper.CreateCells(dgv_ResultOutput);
                            drNorma.CreateCells(dgv_ResultOutput);
                            drLower.CreateCells(dgv_ResultOutput);
                            drUpper.ReadOnly = true;
                            drNorma.ReadOnly = true;
                            drLower.ReadOnly = true;

                            //USL前端
                            drUpper.Cells[0].Value = "Tol(+)";
                            drUpper.Cells[1].Value = "-";
                            drUpper.Cells[2].Value = "-";
                            drUpper.Cells[3].Value = "-";

                            drUpper.Cells[0].Style.BackColor = Color.Black;
                            drUpper.Cells[1].Style.BackColor = Color.Black;
                            drUpper.Cells[2].Style.BackColor = Color.Black;
                            drUpper.Cells[3].Style.BackColor = Color.Black;

                            drUpper.Cells[0].Style.ForeColor = Color.White;
                            drUpper.Cells[1].Style.ForeColor = Color.White;
                            drUpper.Cells[2].Style.ForeColor = Color.White;
                            drUpper.Cells[3].Style.ForeColor = Color.White;

                            drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[3].Style.Font = new Font("隶书", 12);

                            //Nom前端
                            drNorma.Cells[0].Value = "Target";
                            drNorma.Cells[1].Value = "-";
                            drNorma.Cells[2].Value = "-";
                            drNorma.Cells[3].Value = "-";

                            drNorma.Cells[0].Style.BackColor = Color.Black;
                            drNorma.Cells[1].Style.BackColor = Color.Black;
                            drNorma.Cells[2].Style.BackColor = Color.Black;
                            drNorma.Cells[3].Style.BackColor = Color.Black;

                            drNorma.Cells[0].Style.ForeColor = Color.White;
                            drNorma.Cells[1].Style.ForeColor = Color.White;
                            drNorma.Cells[2].Style.ForeColor = Color.White;
                            drNorma.Cells[3].Style.ForeColor = Color.White;

                            drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[3].Style.Font = new Font("隶书", 12);

                            //LSL前端
                            drLower.Cells[0].Value = "Tol(-)";
                            drLower.Cells[1].Value = "-";
                            drLower.Cells[2].Value = "-";
                            drLower.Cells[3].Value = "-";

                            drLower.Cells[0].Style.BackColor = Color.Black;
                            drLower.Cells[1].Style.BackColor = Color.Black;
                            drLower.Cells[2].Style.BackColor = Color.Black;
                            drLower.Cells[3].Style.BackColor = Color.Black;

                            drLower.Cells[0].Style.ForeColor = Color.White;
                            drLower.Cells[1].Style.ForeColor = Color.White;
                            drLower.Cells[2].Style.ForeColor = Color.White;
                            drLower.Cells[3].Style.ForeColor = Color.White;

                            drLower.Cells[0].Style.Font = new Font("隶书", 12);
                            drLower.Cells[1].Style.Font = new Font("隶书", 12);
                            drLower.Cells[2].Style.Font = new Font("隶书", 12);
                            drLower.Cells[3].Style.Font = new Font("隶书", 12);


                            //判定每个尺寸
                            for(int index = 0; index < dgv_ResultOutput.Columns.Count - 4; index++)
                            {
                                //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                                //获得上限、理论值、下限
                                for(int jj = 0; jj < sizes.Count; jj++)
                                {
                                    if(sizes[jj].SizeName == dgv_ResultOutput.Columns[index + 4].HeaderText)
                                    {
                                        drUpper.Cells[index + 4].Value = sizes[jj].UpperDeviation.ToString("0.0000");
                                        drNorma.Cells[index + 4].Value = sizes[jj].NormValue.ToString("0.0000");

                                        if(sizes[jj].LowerDeviation == 0)
                                        {
                                            drLower.Cells[index + 4].Value = sizes[jj].LowerDeviation.ToString("0.0000");
                                        }
                                        else
                                        {
                                            drLower.Cells[index + 4].Value = "-" + sizes[jj].LowerDeviation.ToString("0.0000");
                                        }

                                        drUpper.Cells[index + 4].Style.BackColor = Color.Black;
                                        drNorma.Cells[index + 4].Style.BackColor = Color.Black;
                                        drLower.Cells[index + 4].Style.BackColor = Color.Black;

                                        drUpper.Cells[index + 4].Style.ForeColor = Color.White;
                                        drNorma.Cells[index + 4].Style.ForeColor = Color.White;
                                        drLower.Cells[index + 4].Style.ForeColor = Color.White;

                                        drUpper.Cells[index + 4].Style.Font = new Font("隶书", 12);
                                        drNorma.Cells[index + 4].Style.Font = new Font("隶书", 12);
                                        drLower.Cells[index + 4].Style.Font = new Font("隶书", 12);
                                    }
                                }
                            }
                            dgv_ResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                            dgv_ResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                            dgv_ResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                            dgv_ResultOutput.Rows[2].Frozen = true;      //冻结前三行
                        }
                        catch(Exception exc)
                        {
                        }
                        #endregion
                    }

                    dgv_ResultOutput.Rows.Insert(3, dr);    //插入的数据作为第一行显示

                    //OK品
                    Common.TotalCount++;
                    tb_Result.Text = "OK";
                    tb_Result.ForeColor = Color.Green;

                    AddResultsToChart(chart1, lbl_CT, lbl_Total, OKLab, NGLab, NALab);
                }));
                //SaveYieldToIni();
            }
            catch(Exception exc)
            {
            }

        }


        /// <summary>
        /// 更新NG数据到界面
        /// </summary>
        /// <param name="camaraDataList">当前测试产品的数据</param>
        private async void UpdataNGUI (MeasureProduct product)
        {
            List<DataItem> camaraDataList = product.MeasureData;
            if(camaraDataList == null)
            { return; }
            DataGridViewRow dr = new DataGridViewRow();
            string jugeRet = JUDGEMENT_RESULT.NG.ToString();
            await Task.Run(() =>
            {

                Common.NGCount++;

                //新增加一行在第一行
                dr.CreateCells(dgv_NGResultOutput);

                //插入时间
                dr.Cells[1].Value = product.NG_FAI;
                dr.Cells[2].Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                dr.Cells[3].Value = product.SN;
                dr.Cells[4].Value = product.Position;

                dr.Cells[0].Style.BackColor = Color.Black;
                dr.Cells[1].Style.BackColor = Color.Black;
                dr.Cells[2].Style.BackColor = Color.Black;
                dr.Cells[3].Style.BackColor = Color.Black;
                dr.Cells[4].Style.BackColor = Color.Black;

                dr.Cells[1].Style.ForeColor = Color.LawnGreen;
                dr.Cells[2].Style.ForeColor = Color.LawnGreen;
                dr.Cells[3].Style.ForeColor = Color.LawnGreen;
                dr.Cells[4].Style.ForeColor = Color.LawnGreen;

                dr.Cells[1].Style.Font = new Font("隶书", 12);
                dr.Cells[2].Style.Font = new Font("隶书", 12);
                dr.Cells[3].Style.Font = new Font("隶书", 12);
                dr.Cells[4].Style.Font = new Font("隶书", 12);

                if(product.MesInfo != "true")
                {
                    dr.Cells[0].Style.ForeColor = Color.Red;
                }

                foreach(DataItem camaraData in camaraDataList)
                {
                    if(!nameList.Contains(camaraData.Name))
                        continue;

                    //bool ret = AddResults(Common.TotalCount, camaraData);
                    //if (ret == false)
                    //{
                    //    continue;
                    //}

                    //判定每个尺寸
                    for(int index = 0; index < dgv_NGResultOutput.Columns.Count - 5; index++)
                    {
                        string[] str_FAI = dgv_NGResultOutput.Columns[index + 5].HeaderText.Split(',', '\n', '(', '|', ')');
                        if(str_FAI[0] != camaraData.Name)
                        {
                            continue;
                        }

                        //cell颜色改变
                        if(camaraData.JugeResult == JUDGEMENT_RESULT.NG.ToString() ||
                            camaraData.JugeResult == JUDGEMENT_RESULT.EXCEPTION.ToString() ||
                            camaraData.JugeResult == JUDGEMENT_RESULT.NA.ToString())//NG or EXCEPTION orNA
                        {
                            dr.Cells[index + 5].Style.BackColor = Color.Black;
                            dr.Cells[index + 5].Style.ForeColor = Color.Red;
                            dr.Cells[1].Style.ForeColor = Color.Red;
                        }
                        else
                        {
                            dr.Cells[index + 5].Style.BackColor = Color.Black;
                            dr.Cells[index + 5].Style.ForeColor = Color.LawnGreen;
                        }

                        singleSizeTotals[index]++;

                        if(camaraData.JugeResult == JUDGEMENT_RESULT.EXCEPTION.ToString() ||
                            camaraData.JugeResult == JUDGEMENT_RESULT.NA.ToString())
                        {
                            if(cb_isShowException.CheckState == CheckState.Checked)//如果需要区分异常
                            {
                                if(camaraData.JugeResult == JUDGEMENT_RESULT.EXCEPTION.ToString())
                                {
                                    jugeRet += JUDGEMENT_RESULT.EXCEPTION.ToString();//判定结果为异常
                                }
                                else if(camaraData.JugeResult == JUDGEMENT_RESULT.NA.ToString())
                                {
                                    jugeRet += JUDGEMENT_RESULT.NA.ToString();//判定结果为异常
                                }

                                singleSizeTotals[index]--;//不计入总数
                            }
                            else
                            {
                                jugeRet += JUDGEMENT_RESULT.NG.ToString();//否者判定为NG
                                singleSizeNGCount[index]++;
                            }
                        }
                        if(camaraData.JugeResult == JUDGEMENT_RESULT.NG.ToString())
                        {
                            jugeRet += JUDGEMENT_RESULT.NG.ToString();
                            singleSizeNGCount[index]++;
                        }

                        camaraData.Value = Math.Round(camaraData.Value, 4);
                        //插入该尺寸
                        if(camaraData.Value > 999)
                        {
                            dr.Cells[index + 5].Value = "NA";
                        }
                        else
                        {
                            if(camaraData.Name.Contains("SAMPLE"))
                            { dr.Cells[index + 5].Value = camaraData.Value.ToString("0"); }
                            else
                            { dr.Cells[index + 5].Value = camaraData.Value.ToString("0.0000"); }//
                        }

                        //计算单个尺寸的良率
                        // if (singleSizeTotals[index] == 0) continue;//不用计算
                        if(singleSizeTotals[index] != 0)
                        {
                            singleSizeYields[index] = (singleSizeTotals[index] - singleSizeNGCount[index]) / Convert.ToDouble(singleSizeTotals[index]);
                        }
                        else
                        {
                            singleSizeYields[index] = 0;
                        }

                        dr.Cells[index + 5].Style.Font = new Font("隶书", 12);//0902add

                        //单个尺寸的良率显示
                        dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.BackColor = Color.Black;
                        dgv_ResultOutputRote.Rows[0].Cells[index + 1].Style.ForeColor = Color.LawnGreen;
                        dgv_ResultOutputRote.Rows[0].Cells[index + 1].Value = (singleSizeYields[index] * 100).ToString("f2") + "%";


                        //单个尺寸的测量总数显示
                        dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.BackColor = Color.Black;
                        dgv_ResultOutputRote.Rows[1].Cells[index + 1].Style.ForeColor = Color.LawnGreen;
                        dgv_ResultOutputRote.Rows[1].Cells[index + 1].Value = singleSizeTotals[index].ToString();

                        //单个尺寸的测量的OK数的显示
                        dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.BackColor = Color.Black;
                        dgv_ResultOutputRote.Rows[2].Cells[index + 1].Style.ForeColor = Color.LawnGreen;
                        dgv_ResultOutputRote.Rows[2].Cells[index + 1].Value = (singleSizeTotals[index] - singleSizeNGCount[index]).ToString();

                        //单个尺寸的测量的NG数的显示
                        dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.BackColor = Color.Black;
                        dgv_ResultOutputRote.Rows[3].Cells[index + 1].Style.ForeColor = Color.LawnGreen;
                        dgv_ResultOutputRote.Rows[3].Cells[index + 1].Value = singleSizeNGCount[index].ToString();
                    }

                }
            });

            BeginInvoke(new Action(() =>
            {
                try
                {
                    txtBarcode.Text = product.SN;
                    if(dgv_NGResultOutput.Rows.Count >= 64)
                    {
                        #region 建立尺寸上下限固定行
                        dgv_NGResultOutput.Rows.Clear();
                        try
                        {
                            DataGridViewRow drUpper = new DataGridViewRow();
                            DataGridViewRow drNorma = new DataGridViewRow();
                            DataGridViewRow drLower = new DataGridViewRow();
                            drUpper.CreateCells(dgv_NGResultOutput);
                            drNorma.CreateCells(dgv_NGResultOutput);
                            drLower.CreateCells(dgv_NGResultOutput);
                            drUpper.ReadOnly = true;
                            drNorma.ReadOnly = true;
                            drLower.ReadOnly = true;

                            //USL前端
                            drUpper.Cells[0].Value = "Tol(+)";
                            drUpper.Cells[1].Value = "-";
                            drUpper.Cells[2].Value = "-";
                            drUpper.Cells[3].Value = "-";
                            drUpper.Cells[4].Value = "-";

                            drUpper.Cells[0].Style.BackColor = Color.Black;
                            drUpper.Cells[1].Style.BackColor = Color.Black;
                            drUpper.Cells[2].Style.BackColor = Color.Black;
                            drUpper.Cells[3].Style.BackColor = Color.Black;
                            drUpper.Cells[4].Style.BackColor = Color.Black;

                            drUpper.Cells[0].Style.ForeColor = Color.White;
                            drUpper.Cells[1].Style.ForeColor = Color.White;
                            drUpper.Cells[2].Style.ForeColor = Color.White;
                            drUpper.Cells[3].Style.ForeColor = Color.White;
                            drUpper.Cells[4].Style.ForeColor = Color.White;

                            drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[3].Style.Font = new Font("隶书", 12);
                            drUpper.Cells[4].Style.Font = new Font("隶书", 12);


                            //Nom前端
                            drNorma.Cells[0].Value = "Target";
                            drNorma.Cells[1].Value = "-";
                            drNorma.Cells[2].Value = "-";
                            drNorma.Cells[3].Value = "-";
                            drNorma.Cells[4].Value = "-";

                            drNorma.Cells[0].Style.BackColor = Color.Black;
                            drNorma.Cells[1].Style.BackColor = Color.Black;
                            drNorma.Cells[2].Style.BackColor = Color.Black;
                            drNorma.Cells[3].Style.BackColor = Color.Black;
                            drNorma.Cells[4].Style.BackColor = Color.Black;

                            drNorma.Cells[0].Style.ForeColor = Color.White;
                            drNorma.Cells[1].Style.ForeColor = Color.White;
                            drNorma.Cells[2].Style.ForeColor = Color.White;
                            drNorma.Cells[3].Style.ForeColor = Color.White;
                            drNorma.Cells[4].Style.ForeColor = Color.White;

                            drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[3].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[4].Style.Font = new Font("隶书", 12);

                            //LSL前端
                            drLower.Cells[0].Value = "Tol(-)";
                            drLower.Cells[1].Value = "-";
                            drLower.Cells[2].Value = "-";
                            drLower.Cells[3].Value = "-";
                            drLower.Cells[4].Value = "-";

                            drLower.Cells[0].Style.BackColor = Color.Black;
                            drLower.Cells[1].Style.BackColor = Color.Black;
                            drLower.Cells[2].Style.BackColor = Color.Black;
                            drLower.Cells[3].Style.BackColor = Color.Black;
                            drLower.Cells[4].Style.BackColor = Color.Black;

                            drLower.Cells[0].Style.ForeColor = Color.White;
                            drLower.Cells[1].Style.ForeColor = Color.White;
                            drLower.Cells[2].Style.ForeColor = Color.White;
                            drLower.Cells[3].Style.ForeColor = Color.White;
                            drLower.Cells[4].Style.ForeColor = Color.White;

                            drLower.Cells[0].Style.Font = new Font("隶书", 12);
                            drLower.Cells[1].Style.Font = new Font("隶书", 12);
                            drLower.Cells[2].Style.Font = new Font("隶书", 12);
                            drLower.Cells[3].Style.Font = new Font("隶书", 12);
                            drLower.Cells[4].Style.Font = new Font("隶书", 12);


                            //判定每个尺寸
                            for(int index = 0; index < dgv_NGResultOutput.Columns.Count - 5; index++)
                            {
                                //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                                //获得上限、理论值、下限
                                for(int jj = 0; jj < sizes.Count; jj++)
                                {
                                    if(sizes[jj].SizeName == dgv_NGResultOutput.Columns[index + 5].HeaderText)
                                    {
                                        drUpper.Cells[index + 5].Value = sizes[jj].UpperDeviation.ToString("0.0000");
                                        drNorma.Cells[index + 5].Value = sizes[jj].NormValue.ToString("0.0000");

                                        if(sizes[jj].LowerDeviation == 0)
                                        {
                                            drLower.Cells[index + 5].Value = sizes[jj].LowerDeviation.ToString("0.0000");
                                        }
                                        else
                                        {
                                            drLower.Cells[index + 5].Value = "-" + sizes[jj].LowerDeviation.ToString("0.0000");
                                        }

                                        drUpper.Cells[index + 5].Style.BackColor = Color.Black;
                                        drNorma.Cells[index + 5].Style.BackColor = Color.Black;
                                        drLower.Cells[index + 5].Style.BackColor = Color.Black;

                                        drUpper.Cells[index + 5].Style.ForeColor = Color.White;
                                        drNorma.Cells[index + 5].Style.ForeColor = Color.White;
                                        drLower.Cells[index + 5].Style.ForeColor = Color.White;

                                        drUpper.Cells[index + 5].Style.Font = new Font("隶书", 12);
                                        drNorma.Cells[index + 5].Style.Font = new Font("隶书", 12);
                                        drLower.Cells[index + 5].Style.Font = new Font("隶书", 12);
                                    }
                                }
                            }
                            dgv_NGResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                            dgv_NGResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                            dgv_NGResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                            dgv_NGResultOutput.Rows[2].Frozen = true;      //冻结前三行
                        }
                        catch(Exception exc)
                        {
                        }
                        #endregion

                    }

                    dgv_NGResultOutput.Rows.Insert(3, dr);    //插入的数据作为第一行显示

                    //单个产品的判定
                    Common.TotalCount++;

                    //Common.NGCount++;

                    if(jugeRet.Contains(JUDGEMENT_RESULT.EXCEPTION.ToString()))
                    {
                        Common.ExceptionCount++;
                        //Common.TotalCount++;
                        tb_Result.Text = "NG";
                        tb_Result.ForeColor = Color.Red;
                    }
                    else if(jugeRet.Contains(JUDGEMENT_RESULT.NG.ToString()))
                    {
                        //Common.NGCount++;
                        //Common.TotalCount++;
                        tb_Result.Text = "NG";
                        tb_Result.ForeColor = Color.Red;
                    }
                    else if(jugeRet.Contains(JUDGEMENT_RESULT.NA.ToString()))
                    {
                        //Common.NGCount++;
                        //Common.TotalCount++;
                        tb_Result.Text = "NG";
                        tb_Result.ForeColor = Color.Red;
                    }
                    else
                    {
                        //Common.TotalCount++;
                        tb_Result.Text = "OK";
                        tb_Result.ForeColor = Color.Green;
                    }
                    //根据产品判定结果显示尺寸号
#if false
                    for (int index = 0; index < dgv_ResultOutput.Rows.Count; index++)
                    {
                        //
                        dgv_ResultOutput.Rows[index].Cells[0].Value = Common.TotalCount;
                    }

#endif
                    //AddResultsProgress(bar1, jugeResult);
                    //Thread.Sleep(20);
                    AddResultsToChart(chart1, lbl_CT, lbl_Total, OKLab, NGLab, NALab);
                    // SaveYieldToIni();
                    //Thread.Sleep(20);
                    //Application.DoEvents();
                }
                catch(Exception exc)
                {
                }
            }));
        }

        /// <summary>
        /// 监控窗体点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == tsmi_MothionDebug)//工站步骤监控
            {
                Frm_StationDebug stationDebugFrm = Frm_StationDebug.Instance;
                stationDebugFrm.Show();
            }
            if (e.ClickedItem == tsmi_MonitorVar)//运行时变量监控
            {
                Frm_VarMonitor varMonitorFrm = new Frm_VarMonitor();
                varMonitorFrm.Show();
            }
            if (e.ClickedItem == tsmi_MonitorTask)//线程状态监控
            {
                Frm_TaskMonitor taskMonitorForm = new Frm_TaskMonitor();
                taskMonitorForm.Show();
            }
        }

        /// <summary>
        /// Chart图表 清空重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chart1_DoubleClick(object sender, EventArgs e)
        {
            FileUtils.ClearFile(INIUtils.Path);
            Common.NGCount = 0;
            Common.TotalCount = 0;
            Common.NACount = 0;
            Common.ExceptionCount = 0;

            for (int i = 0; i < singleSizeTotals.Length; i++)
            {
                singleSizeTotals[i] = 0;
                singleSizeYields[i] = 0;
                singleSizeNGCount[i] = 0;
            }

            AddResultsToChart(chart1, lbl_CT, lbl_Total, OKLab, NGLab, NALab);

            dgv_ResultOutput.Rows.Clear();
            dgv_NGResultOutput.Rows.Clear();
            dgv_ResultOutputRote.Rows.Clear();

            #region 建立OK UI尺寸上下限固定行
            dgv_ResultOutput.Rows.Clear();
            try
            {
                DataGridViewRow drUpper = new DataGridViewRow();
                DataGridViewRow drNorma = new DataGridViewRow();
                DataGridViewRow drLower = new DataGridViewRow();
                drUpper.CreateCells(dgv_ResultOutput);
                drNorma.CreateCells(dgv_ResultOutput);
                drLower.CreateCells(dgv_ResultOutput);
                drUpper.ReadOnly = true;
                drNorma.ReadOnly = true;
                drLower.ReadOnly = true;

                //USL前端
                drUpper.Cells[0].Value = "Tol(+)";
                drUpper.Cells[1].Value = "-";
                drUpper.Cells[2].Value = "-";
                drUpper.Cells[3].Value = "-";

                drUpper.Cells[0].Style.BackColor = Color.Black;
                drUpper.Cells[1].Style.BackColor = Color.Black;
                drUpper.Cells[2].Style.BackColor = Color.Black;
                drUpper.Cells[3].Style.BackColor = Color.Black;

                drUpper.Cells[0].Style.ForeColor = Color.White;
                drUpper.Cells[1].Style.ForeColor = Color.White;
                drUpper.Cells[2].Style.ForeColor = Color.White;
                drUpper.Cells[3].Style.ForeColor = Color.White;

                drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                drUpper.Cells[3].Style.Font = new Font("隶书", 12);

                //Nom前端
                drNorma.Cells[0].Value = "Target";
                drNorma.Cells[1].Value = "-";
                drNorma.Cells[2].Value = "-";
                drNorma.Cells[3].Value = "-";

                drNorma.Cells[0].Style.BackColor = Color.Black;
                drNorma.Cells[1].Style.BackColor = Color.Black;
                drNorma.Cells[2].Style.BackColor = Color.Black;
                drNorma.Cells[3].Style.BackColor = Color.Black;

                drNorma.Cells[0].Style.ForeColor = Color.White;
                drNorma.Cells[1].Style.ForeColor = Color.White;
                drNorma.Cells[2].Style.ForeColor = Color.White;
                drNorma.Cells[3].Style.ForeColor = Color.White;

                drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                drNorma.Cells[3].Style.Font = new Font("隶书", 12);

                //LSL前端
                drLower.Cells[0].Value = "Tol(-)";
                drLower.Cells[1].Value = "-";
                drLower.Cells[2].Value = "-";
                drLower.Cells[3].Value = "-";

                drLower.Cells[0].Style.BackColor = Color.Black;
                drLower.Cells[1].Style.BackColor = Color.Black;
                drLower.Cells[2].Style.BackColor = Color.Black;
                drLower.Cells[3].Style.BackColor = Color.Black;

                drLower.Cells[0].Style.ForeColor = Color.White;
                drLower.Cells[1].Style.ForeColor = Color.White;
                drLower.Cells[2].Style.ForeColor = Color.White;
                drLower.Cells[3].Style.ForeColor = Color.White;

                drLower.Cells[0].Style.Font = new Font("隶书", 12);
                drLower.Cells[1].Style.Font = new Font("隶书", 12);
                drLower.Cells[2].Style.Font = new Font("隶书", 12);
                drLower.Cells[3].Style.Font = new Font("隶书", 12);


                //判定每个尺寸
                for (int index = 0; index < dgv_ResultOutput.Columns.Count - 4; index++)
                {
                    //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                    //获得上限、理论值、下限
                    for (int jj = 0; jj < sizes.Count; jj++)
                    {
                        if (sizes[jj].SizeName == dgv_ResultOutput.Columns[index + 4].HeaderText)
                        {
                            drUpper.Cells[index + 4].Value = sizes[jj].UpperDeviation.ToString();//"0.000"
                            drNorma.Cells[index + 4].Value = sizes[jj].NormValue.ToString();

                            if (sizes[jj].LowerDeviation == 0)
                            {
                                drLower.Cells[index + 4].Value = sizes[jj].LowerDeviation.ToString();
                            }
                            else
                            {
                                drLower.Cells[index + 4].Value = "-" + sizes[jj].LowerDeviation.ToString();
                            }

                            drUpper.Cells[index + 4].Style.BackColor = Color.Black;
                            drNorma.Cells[index + 4].Style.BackColor = Color.Black;
                            drLower.Cells[index + 4].Style.BackColor = Color.Black;

                            drUpper.Cells[index + 4].Style.ForeColor = Color.White;
                            drNorma.Cells[index + 4].Style.ForeColor = Color.White;
                            drLower.Cells[index + 4].Style.ForeColor = Color.White;

                            drUpper.Cells[index + 4].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[index + 4].Style.Font = new Font("隶书", 12);
                            drLower.Cells[index + 4].Style.Font = new Font("隶书", 12);
                        }
                    }
                }
                dgv_ResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                dgv_ResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                dgv_ResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                dgv_ResultOutput.Rows[2].Frozen = true;      //冻结前三行
            }
            catch (Exception exc)
            {
            }
            #endregion

            #region 建立NG UI尺寸上下限固定行
            dgv_NGResultOutput.Rows.Clear();
            try
            {
                DataGridViewRow drUpper = new DataGridViewRow();
                DataGridViewRow drNorma = new DataGridViewRow();
                DataGridViewRow drLower = new DataGridViewRow();
                drUpper.CreateCells(dgv_NGResultOutput);
                drNorma.CreateCells(dgv_NGResultOutput);
                drLower.CreateCells(dgv_NGResultOutput);
                drUpper.ReadOnly = true;
                drNorma.ReadOnly = true;
                drLower.ReadOnly = true;

                //USL前端
                drUpper.Cells[0].Value = "Tol(+)";
                drUpper.Cells[1].Value = "-";
                drUpper.Cells[2].Value = "-";
                drUpper.Cells[3].Value = "-";
                drUpper.Cells[4].Value = "-";

                drUpper.Cells[0].Style.BackColor = Color.Black;
                drUpper.Cells[1].Style.BackColor = Color.Black;
                drUpper.Cells[2].Style.BackColor = Color.Black;
                drUpper.Cells[3].Style.BackColor = Color.Black;
                drUpper.Cells[4].Style.BackColor = Color.Black;

                drUpper.Cells[0].Style.ForeColor = Color.White;
                drUpper.Cells[1].Style.ForeColor = Color.White;
                drUpper.Cells[2].Style.ForeColor = Color.White;
                drUpper.Cells[3].Style.ForeColor = Color.White;
                drUpper.Cells[4].Style.ForeColor = Color.White;

                drUpper.Cells[0].Style.Font = new Font("隶书", 12);
                drUpper.Cells[1].Style.Font = new Font("隶书", 12);
                drUpper.Cells[2].Style.Font = new Font("隶书", 12);
                drUpper.Cells[3].Style.Font = new Font("隶书", 12);
                drUpper.Cells[4].Style.Font = new Font("隶书", 12);

                //Nom前端
                drNorma.Cells[0].Value = "Target";
                drNorma.Cells[1].Value = "-";
                drNorma.Cells[2].Value = "-";
                drNorma.Cells[3].Value = "-";
                drNorma.Cells[4].Value = "-";

                drNorma.Cells[0].Style.BackColor = Color.Black;
                drNorma.Cells[1].Style.BackColor = Color.Black;
                drNorma.Cells[2].Style.BackColor = Color.Black;
                drNorma.Cells[3].Style.BackColor = Color.Black;
                drNorma.Cells[4].Style.BackColor = Color.Black;

                drNorma.Cells[0].Style.ForeColor = Color.White;
                drNorma.Cells[1].Style.ForeColor = Color.White;
                drNorma.Cells[2].Style.ForeColor = Color.White;
                drNorma.Cells[3].Style.ForeColor = Color.White;
                drNorma.Cells[4].Style.ForeColor = Color.White;

                drNorma.Cells[0].Style.Font = new Font("隶书", 12);
                drNorma.Cells[1].Style.Font = new Font("隶书", 12);
                drNorma.Cells[2].Style.Font = new Font("隶书", 12);
                drNorma.Cells[3].Style.Font = new Font("隶书", 12);
                drNorma.Cells[4].Style.Font = new Font("隶书", 12);

                //LSL前端
                drLower.Cells[0].Value = "Tol(-)";
                drLower.Cells[1].Value = "-";
                drLower.Cells[2].Value = "-";
                drLower.Cells[3].Value = "-";
                drLower.Cells[4].Value = "-";

                drLower.Cells[0].Style.BackColor = Color.Black;
                drLower.Cells[1].Style.BackColor = Color.Black;
                drLower.Cells[2].Style.BackColor = Color.Black;
                drLower.Cells[3].Style.BackColor = Color.Black;
                drLower.Cells[4].Style.BackColor = Color.Black;

                drLower.Cells[0].Style.ForeColor = Color.White;
                drLower.Cells[1].Style.ForeColor = Color.White;
                drLower.Cells[2].Style.ForeColor = Color.White;
                drLower.Cells[3].Style.ForeColor = Color.White;
                drLower.Cells[4].Style.ForeColor = Color.White;

                drLower.Cells[0].Style.Font = new Font("隶书", 12);
                drLower.Cells[1].Style.Font = new Font("隶书", 12);
                drLower.Cells[2].Style.Font = new Font("隶书", 12);
                drLower.Cells[3].Style.Font = new Font("隶书", 12);
                drLower.Cells[4].Style.Font = new Font("隶书", 12);


                //判定每个尺寸
                for (int index = 0; index < dgv_NGResultOutput.Columns.Count - 5; index++)
                {
                    //string[] str_FAI = dgv_ResultOutput.Columns[index + 4].HeaderText.Split(',', '\n', '(', '|', ')')
                    //获得上限、理论值、下限
                    for (int jj = 0; jj < sizes.Count; jj++)
                    {
                        if (sizes[jj].SizeName == dgv_NGResultOutput.Columns[index + 5].HeaderText)
                        {
                            drUpper.Cells[index + 5].Value = sizes[jj].UpperDeviation.ToString();
                            drNorma.Cells[index + 5].Value = sizes[jj].NormValue.ToString();

                            if (sizes[jj].LowerDeviation == 0)
                            {
                                drLower.Cells[index + 5].Value = sizes[jj].LowerDeviation.ToString();
                            }
                            else
                            {
                                drLower.Cells[index + 5].Value = "-" + sizes[jj].LowerDeviation.ToString();
                            }

                            drUpper.Cells[index + 5].Style.BackColor = Color.Black;
                            drNorma.Cells[index + 5].Style.BackColor = Color.Black;
                            drLower.Cells[index + 5].Style.BackColor = Color.Black;

                            drUpper.Cells[index + 5].Style.ForeColor = Color.White;
                            drNorma.Cells[index + 5].Style.ForeColor = Color.White;
                            drLower.Cells[index + 5].Style.ForeColor = Color.White;

                            drUpper.Cells[index + 5].Style.Font = new Font("隶书", 12);
                            drNorma.Cells[index + 5].Style.Font = new Font("隶书", 12);
                            drLower.Cells[index + 5].Style.Font = new Font("隶书", 12);
                        }
                    }
                }
                dgv_NGResultOutput.Rows.Insert(0, drLower);    //插入的数据作为第一行显示
                dgv_NGResultOutput.Rows.Insert(0, drNorma);    //插入的数据作为第二行显示
                dgv_NGResultOutput.Rows.Insert(0, drUpper);    //插入的数据作为第三行显示
                dgv_NGResultOutput.Rows[2].Frozen = true;      //冻结前三行
            }
            catch (Exception exc)
            {
            }
            #endregion

            #region 初始化显示良率表的行头
            string[] RowName = new string[4];

            RowName[0] = "Yield";
            dgv_ResultOutputRote.ReadOnly = true;
            dgv_ResultOutputRote.BackgroundColor = Color.Black;
            dgv_ResultOutputRote.ForeColor = Color.Green;
            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "Total";
            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "OK";
            dgv_ResultOutputRote.Rows.Add(RowName);
            RowName[0] = "NG";
            dgv_ResultOutputRote.Rows.Add(RowName);

            dgv_ResultOutputRote.Rows[0].DefaultCellStyle.BackColor = Color.Black;
            dgv_ResultOutputRote.Rows[1].DefaultCellStyle.BackColor = Color.Black;
            dgv_ResultOutputRote.Rows[2].DefaultCellStyle.BackColor = Color.Black;
            dgv_ResultOutputRote.Rows[3].DefaultCellStyle.BackColor = Color.Black;

            dgv_ResultOutputRote.Rows[0].Cells[0].Style.ForeColor = Color.Green;
            dgv_ResultOutputRote.Rows[1].Cells[0].Style.ForeColor = Color.Green;
            dgv_ResultOutputRote.Rows[2].Cells[0].Style.ForeColor = Color.Green;
            dgv_ResultOutputRote.Rows[3].Cells[0].Style.ForeColor = Color.Green;
            #endregion

            if (singleSizeTotals != null)
            {
                for (int i = 0; i < singleSizeTotals.Count(); i++)
                {
                    singleSizeTotals[i] = 0;
                    singleSizeNGCount[i] = 0;
                    singleSizeYields[i] = 0;
                }
            }
        }

        #region 数据显示
        private void InitDgvResultList()
        {
            DataGridView dgvResult = dgv_ResultOutput;
            dgvResult.AutoGenerateColumns = false;
            dgvResult.Columns.Clear();
            StringBuilder rowString = new StringBuilder();

            DataGridViewLinkColumn col = new DataGridViewLinkColumn();
            col.DataPropertyName = "SN";
            col.HeaderText = "SN";
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgvResult.Columns.Add(col);

            DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "Color";
            col2.HeaderText = "Color";
            dgvResult.Columns.Add(col2);

            col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "ProRes";
            col2.HeaderText = "ProRes";
            dgvResult.Columns.Add(col2);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResLogo";
            col.HeaderText = "Logo";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResFcam";
            col.HeaderText = "Fcam";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResRcam";
            col.HeaderText = "Rcam";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResTrim";
            col.HeaderText = "Trim";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResPlateau";
            col.HeaderText = "Plateau";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResBG";
            col.HeaderText = "BG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResBRT";
            col.HeaderText = "BRT";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResCG";
            col.HeaderText = "CG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResCRT";
            col.HeaderText = "CRT";
            dgvResult.Columns.Add(col);

            //////////////////////////////////////////
            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResBGColor";
            col.HeaderText = "BGColor";
            dgvResult.Columns.Add(col);

            //col = new DataGridViewLinkColumn();
            //col.DataPropertyName = "ResBGRT";
            //col.HeaderText = "BGRT";
            //dgvResult.Columns.Add(col);

            //col = new DataGridViewLinkColumn();
            //col.DataPropertyName = "ResCGRT";
            //col.HeaderText = "CGRT";
            //dgvResult.Columns.Add(col);
            ////////////////////////////////////////////////

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "HB_CG";
            col.HeaderText = "HB_CG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VUVD_CG";
            col.HeaderText = "VUVD_CG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "HB";
            col.HeaderText = "HB";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VUVD_BG";
            col.HeaderText = "VUVD_BG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "HB_BG";
            col.HeaderText = "HB_BG";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VUVD";
            col.HeaderText = "VUVD";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "RB_U";
            col.HeaderText = "RB_U";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VU_U";
            col.HeaderText = "VU_U";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VD_U";
            col.HeaderText = "VD_U";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "HB_U";
            col.HeaderText = "HB_U";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "HB_D";
            col.HeaderText = "HB_D";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "RB_D";
            col.HeaderText = "RB_D";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VU_D";
            col.HeaderText = "VU_D";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "VD_D";
            col.HeaderText = "VD_D";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Left_1";
            col.HeaderText = "Band_Left_1";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Right_2";
            col.HeaderText = "Band_Right_2";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Right_1";
            col.HeaderText = "Band_Right_1";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Left_2";
            col.HeaderText = "Band_Left_2";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Top";
            col.HeaderText = "Band_Top";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Bottom";
            col.HeaderText = "Band_Bottom";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Corner_3";
            col.HeaderText = "Band_Corner_3";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Corner_2";
            col.HeaderText = "Band_Corner_2";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Corner_1";
            col.HeaderText = "Band_Corner_1";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "Band_Corner_4";
            col.HeaderText = "Band_Corner_4";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResBand1";
            col.HeaderText = "Band1";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResMesh";
            col.HeaderText = "Mesh";
            dgvResult.Columns.Add(col);

            col = new DataGridViewLinkColumn();
            col.DataPropertyName = "ResBand2";
            col.HeaderText = "Band2";
            dgvResult.Columns.Add(col);

            col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "InputTime";
            col2.HeaderText = "InputTime";
            dgvResult.Columns.Add(col2);
            col2.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "OutputTime";
            col2.HeaderText = "OutputTime";
            dgvResult.Columns.Add(col2);
            col2.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            //col = new DataGridViewLinkColumn();
            //col.DataPropertyName = "ID";
            //col.HeaderText = "ID";
            //col.Visible = false;
            //dgvResult.Columns.Add(col);

        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void dgv_proList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {


        }

        #endregion

        private static void WriteLogToTxt(string strLog, string Path)
        {

            String System_Now_Time = null;
            String File_Create_Time = null;

            System_Now_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"); //"HH:mm:ss
            File_Create_Time = DateTime.Now.ToString("yyyyMMdd");
            string logDocument = File_Create_Time + ".txt";

            string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string logFilePath = str.Substring(0, str.LastIndexOf("\\")) + "//" + Path;//VisionSendMessage";
            if (!Directory.Exists(logFilePath))
            {
                Directory.CreateDirectory(logFilePath);
            }
            logFilePath = logFilePath + "//" + logDocument;
            FileStream fs = new FileStream(logFilePath, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            sw.WriteLine(System_Now_Time + ":   " + strLog);
            sw.Flush();
            sw.Close();
            fs.Close();

        }

    }
}

